<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/5/24
 * Time: 12:01
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\api\controller;


use app\common\lib\Show;
use app\common\lib\Status;
use app\common\validate\User;
use app\common\business\Sms as BusObj;
use think\App;

class Sms extends BaseApi
{
    protected $busObj = null;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->busObj = new BusObj();
    }

    public function code()
    {
        $phone_number = $this->request->param('phone_number', '', 'trim');
        $data = [
            "phone_number" => $phone_number
        ];
        $validate = new User();
        if (!$validate->scene('sms')->check($data)) {
            return Show::json_show(Status::Error, $validate->getError());
        }
        try {
            $result = $this->busObj->sendCode($data['phone_number'],'ali');
        } catch (\Exception $e) {
            return Show::json_show(Status::Error, $e->getMessage());
        }
        if ($result) {
            return Show::json_show(Status::Success, "验证码发送成功");
        } else {
            return Show::json_show(Status::Error, "验证码发送失败");
        }
    }
}